package com.itqf.mapper;

import com.itqf.entity.Emp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

/**
 * @Description:  注解
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/6
 * @Time: 上午11:41
 */
public interface EmpMapper {

    @Select("select * from emp")
    public List<Emp> findAll();

    //@Options(useGeneratedKeys = true,keyColumn = "emp_id",keyProperty = "empId")
    @Insert("insert into emp(name,sex,age,salary,d_id) value(#{name},#{sex},#{age},#{salary},#{dId})")
    @SelectKey(keyColumn = "emp_id",statement = "select last_insert_id()",keyProperty = "empId",resultType = Integer.class,before = false)
    public int insert(Emp emp);

   // @Update()

    /**
     * ${} 应用场景
     * @param column
     * @param orderRole
     * @return
     */
    @Select("select * from emp order by ${columnName} ${orderRule}")// 拼接sql方式
    public List<Emp> findAllOrder(@Param("columnName")String column,@Param("orderRule")String  orderRole);

    @Select("select * from emp order by #{columnName} #{orderRule}")//占位符方式  排序不生效
    public List<Emp> findAllOrder1(@Param("columnName")String column,@Param("orderRule")String  orderRole);


}
